<script setup>
import { ref } from 'vue'
import useUserInfoStore from '@/stores/userInfo.js'
const userInfoStore = useUserInfoStore();

const userInfo = ref({...userInfoStore.info})
const rules = {
    old_pwd: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '密码必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ],
    new_pwd: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '密码必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ],
    re_pwd: [
        { required: true, message: '请输入密码', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '密码必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ]
}

const updatepwd = ref({
    old_pwd : '',
    new_pwd : '',
    re_pwd : ''
})
//修改个人信息
import {pwdUpdateService} from '@/api/user.js'
import {ElMessage} from 'element-plus'
//修改密码
const updateUserPwd = async ()=>{
    //调用接口
    let result = await pwdUpdateService(updatepwd.value);
    ElMessage.success(result.msg? result.msg : '修改成功');
}

</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>重置密码</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="updatepwd" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="旧密码" prop="old_pwd">
                        <el-input placeholder="输入旧密码" v-model="updatepwd.old_pwd"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码" prop="new_pwd">
                        <el-input placeholder="输入新密码" v-model="updatepwd.new_pwd"></el-input>
                    </el-form-item>
                    <el-form-item label="确认新密码" prop="re_pwd">
                        <el-input placeholder="再次输入新密码" v-model="updatepwd.re_pwd"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click = "updateUserPwd">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>